package com.chatSystem2;


import com.chatSystem2.ClientReadAndPrint;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;


public class ChatView {

    public static void main(String[] args) {
        new ChatView("xuan");
    }

    String userName;
    JTextField text;
    JTextArea textArea;
    ClientReadAndPrint.ChatViewListen listener;
    public static JButton jButton1;
    public static JButton jButton2;
    public static JButton jButton3;
    public static JButton jButton4;
    public static JButton jButton5;

    public static JButton jButton;

    //构造函数
    public ChatView(String userName){
        this.userName = userName;
        init();
    }

    public static JButton getXuan(){return jButton1; }
    public static JButton getTao(){return jButton2; }
    public static JButton getYuan(){return jButton3; }
    public static JButton getjButton4(){return jButton4;}
    public static JButton getjButton5(){return jButton5;}
    public static JButton getSend(){return jButton; }
    void init(){
        JFrame jFrame = new JFrame("User");
        jFrame.setBounds(500,200,600,330);
        jFrame.setResizable(false);

        JTabbedPane jTabbedPane = new JTabbedPane();
        jTabbedPane.add(jButton1);
        jTabbedPane.add(jButton2);
        jTabbedPane.add(jButton3);
        jTabbedPane.add(jButton4);
        jTabbedPane.add(jButton5);

        JPanel friendPanel = new JPanel();
        friendPanel.add(jTabbedPane);
        JPanel MenuBarPanel = new JPanel();
        JLabel lable = new JLabel("user:" + userName);
        JMenuBar jMenuBar = new JMenuBar();
        JMenu functionMenu = new JMenu("functions");
        JMenuItem OnLineUser = new JMenuItem("On Line User");
        functionMenu.add(OnLineUser);
        JMenu helpMenu = new JMenu("help");
        jMenuBar.add(functionMenu);
        jMenuBar.add(helpMenu);
        MenuBarPanel.add(jMenuBar);
        jButton1 = new JButton("xuan");
        jButton2 = new JButton("tao");
        jButton3 = new JButton("yuan");
        jButton1.setEnabled(false);
        jButton2.setEnabled(false);
        jButton3.setEnabled(false);
        jButton4.setEnabled(false);
        jButton5.setEnabled(false);


        JPanel jPanel = new JPanel();

        textArea = new JTextArea("========Logged In ,Welcome========\n",12,35);
        textArea.setEditable(false);

        JScrollPane scroll = new JScrollPane(textArea);  // 滚轮
        scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);  // 显示垂直条

        jPanel.add(lable);
        jPanel.add(scroll);

        text = new JTextField(20);
        jButton = new JButton("send");

        jPanel.add(text);
        jPanel.add(jButton);


        //设置发送按钮监听
        listener = new ClientReadAndPrint().new ChatViewListen();
        listener.setJTextField(text);
        listener.setJTextArea(textArea);
        listener.setChatViewJf(jFrame);
        text.addActionListener(listener);  // 文本框添加监听
        jButton.addActionListener(listener);  // 按钮添加监听
        jButton1.addActionListener(listener);
        jButton2.addActionListener(listener);
        jButton3.addActionListener(listener);
        jButton4.addActionListener(listener);
        jButton5.addActionListener(listener);

        jFrame.add(jPanel,BorderLayout.CENTER);
        jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jFrame.setVisible(true);
        jFrame.add(MenuBarPanel,BorderLayout.NORTH);
        jFrame.add(friendPanel,BorderLayout.EAST);

    }

}
